System and computer program for inserting records into a database

ABSTRACT

For a data processing system having memory for storing a database, a method, a system and a computer program product for directing the data processing system to process a record to be inserted into the database is disclosed. The database includes a plurality of base tables. The method includes the steps of making a record copy matching the record, for each base table to be selected from the plurality of base tables: providing a base table candidate indication for a selected base table, the base table candidate indication indicating whether the selected base table is a candidate base table that may receive the record, the base table candidate indication being determined on an outcome of executing before triggers and an outcome of testing constraints in association with the record copy, the before triggers and the constraints being associated with the selected base table; and restoring the record copy so that the record copy matches the record before providing a next subsequent base table candidate indication for another base table to be selected.

FIELD OF THE INVENTION

The present invention relates to database management systems. Morespecifically, the present invention relates to database managementsystems which operate to process records for the purpose of insertingthe records into a database.

BACKGROUND

Database Management Systems (DBMS) allow the collection, organization,searching and processing of information in a variety of manners.Typically, data in such DBMS are stored in tables comprising columns,which define fields of information for a record, and rows, containingspecific records of those fields of the database. Many modern DBMSemploy Structured Query Language (SQL) as at least one of the mechanismsby which the DBMS can be controlled, including defining tables andviews.

A view is a result set of records in the database which results from aquery. Typically, a DBMS can perform SQL commands, such as SELECT,UPDATE, INSERT or DELETE against a view without being aware of thedefinition of the view and/or its underlying tables.

One example of a DBMS is the IBM® DB2® Universal Database manufacturedand sold by IBM and the SQL examples used herein employ DB2 SQLstatements. As one of its advanced features, this DBMS permits a UNIONALL view to be created wherein two or more physically separate tablesare logically merged into one view for certain types of processing.Amongst other advantages, this allows large databases which, if storedas a single table would exceed various DBMS and/or hardware limits, toinstead be physically partitioned into a variety of smaller tables. Forexample, if several years global sales data for a corporation is storedin a single table, that table could easily exceed the maximum table sizethat a DBMS will allow. With a UNION ALL view, the corporation cancreate sales data tables for the sales in each month, or for the salesin each quarter, etc. which will result in smaller tables. Yet, thecorporation can process the data stored in these various tables as ifthey were stored in one large table by employing a UNION ALL view.

While the UNION ALL view provides significant advantages, it is howeversubject to some limitations. Specifically, performing INSERT operationsagainst a UNION ALL view can raise issues as it may not be clear whichbase table of the UNION ALL view the INSERT operation should operate onas the constraints of the base tables and/or any before triggersapplicable to them are not known by the UNION ALL view.

Published U.S. Patent application 2003/0204540 to Rielau et al. teachesone method of performing an INSERT against a UNION ALL view. While themethod taught in Rielau et al. provides advantages over other knownmethods for performing INSERTs against UNION ALL views, it can becomputationally expensive to perform.

SUMMARY

It is an object of the present invention to provide a novel product andmethod for inserting entries into a database via a union all view, orthe like, which obviates or mitigates at least one disadvantage of theprior art.

According to a first aspect of the present invention, there is provided,for a database management system to be operatively coupled to a dataprocessing system having memory for storing a database, a method ofprocessing a record to be inserted into the database, the databasecomprising a plurality of base tables, the method including the steps ofmaking a record copy matching the record, for each base table to beselected from the plurality of base tables: providing a base tablecandidate indication for a selected base table, the base table candidateindication indicating whether the selected base table is a candidatebase table that may receive the record, the base table candidateindication being determined on an outcome of executing before triggersand an outcome of testing constraints in association with the recordcopy, the before triggers and the constraints being associated with theselected base table, and restoring the record copy so that the recordcopy matches the record before providing a next subsequent base tablecandidate indication for another base table to be selected.

According to another aspect of the present invention, there is provided,for a database management system to be operatively coupled to a dataprocessing system having memory for storing a database, a computerprogram product for directing the data processing system to process arecord to be inserted into the database, the database comprising aplurality of base tables, the computer program product including acomputer readable medium tangibly embodying computer executable code fordirecting the data processing system, the computer executable codeincluding code for making a record copy matching the record, code to beexecuted for each base table to be selected from the plurality of basetables, the code to be executed including code for providing a basetable candidate indication for a selected base table, the base tablecandidate indication indicating whether the selected base table is acandidate base table that may receive the record, the base tablecandidate indication being determined on an outcome of executing beforetriggers and an outcome of testing constraints in association with therecord copy, the before triggers and the constraints being associatedwith the selected base table, and code for restoring the record copy sothat the record copy matches the record before providing a nextsubsequent base table candidate indication for another base table to beselected.

According to yet another aspect of the present invention, there isprovided, for a database management system to be operatively coupled toa data processing system having memory for storing a database, a methodfor inserting received data into the database through a view constructedfrom a union of two or more base tables, each base table having one ormore constraints defining necessary conditions for at least one field ofthe data to meet for data to be inserted into the respective base tableand including at least one before trigger operable to modify the data ina field before the insertion is performed, the method comprising thesteps of for each field of the received data, adding a first column tothe received data to each hold a copy of the original value of the fieldand copying the original values to the first column, adding a tableidentifier column to the received data to hold an identifier of a basetable and setting the value of each row of the table identifier columnto a predefined value, for each base table in turn, executing all beforetriggers defined for the base table on the received data and determiningfor each row of the received data if the values of the received dataafter the before triggers have been processed meet the identifiedconstraints to insert the row of received data into the base table and,for each row: (a) if the identified constraints are met, determining ifthe table identifier column for that row has the predefined value and:(i) if it does not, marking the row with an error message indicating anambiguous insert error and, (ii) if it does have the predefined value,then changing the value of the table identifier column to indicate thebase table under consideration and copying the original value of eachfield from the first column to the respective field; or (b) if theidentified constraints are not met, copying the original value of eachfield from the first column to the respective identified field; andafter all base tables have been considered, inserting each row ofreceived data with an indication of a base table in the table identifiercolumn into the indicated base table having first processed all beforetriggers defined for the indicated base table.

According to yet another aspect of the present invention, there isprovided for a database management system to be operatively coupled to adata processing system having memory for storing a database, a computerprogram product for directing the data processing system to process arecord to be inserted into the database, the database comprising aplurality of base tables, the computer program product including acomputer readable medium tangibly embodying computer executable code fordirecting the data processing system, the computer executable codeincluding code for making a record copy matching the record, code to beexecuted for each base table to be selected from the plurality of basetables, the code to be executed including code for providing a basetable candidate indication for a selected base table, the base tablecandidate indication indicating whether the selected base table is acandidate base table that may receive the record, the base tablecandidate indication being determined on an outcome of executing beforetriggers and an outcome of testing constraints in association with therecord copy, the before triggers and the constraints being associatedwith the selected base table, and code for restoring the record copy sothat the record copy matches the record before providing a nextsubsequent base table candidate indication for another base table to beselected.

for a database management system to be operatively coupled to a dataprocessing system having memory for storing a database, a computerprogram product fir directing the data processing system to insertreceived data into the database through a view constructed from a unionof two or more base tables, each base table having one or moreconstraints defining necessary conditions for at least one field of thedata to meet for data to be inserted into the respective base table andincluding at least one before trigger operable to modify the data in afield before the insertion is performed, the computer program productincluding a computer readable medium for tangibly transporting computerexecutable code for directing the data processing system, the computerexecutable code including code for adding a first column to the receiveddata to each hold a copy of the original value of the field and copyingthe original values to the first column for each field of the receiveddata, code for adding a table identifier column to the received data tohold an identifier of a base table and setting the value of each row ofthe table identifier column to a predefined value, code for executing,for each base table in turn, all before triggers defined for the basetable on the received data and determining for each row of the receiveddata if the values of the received data after the before triggers havebeen processed meet the identified constraints to insert the row ofreceived data into the base table and, for each row: (a) if theidentified constraints are met, determining if the table identifiercolumn for that row has the predefined value and: (i) if it does not,marking the row with an error message indicating an ambiguous inserterror and, (ii) if it does have the predefined value, then changing thevalue of the table identifier column to indicate the base table underconsideration and copying the original value of each field from thefirst column to the respective field; or (b) if the identifiedconstraints are not met, copying the original value of each field fromthe first column to the respective identified field, and code forinserting each row of received data, after all base tables have beenconsidered, with an indication of a base table in the table identifiercolumn into the indicated base table having first processed all beforetriggers defined for the indicated base table.

BRIEF DESCRIPTION OF THE DRAWINGS

Preferred embodiments of the present invention will now be described, byway of example only, with reference to the attached Figures, wherein:

FIG. 1 shows a row schema from a working table of received data inaccordance with the present invention;

FIG. 2 shows an example of received data in the working table of FIG. 1;

FIG. 3 shows the working table of FIG. 1 after a before trigger definedfor a base table is executed;

FIG. 4 shows the working table of FIG. 3 after processing of the basetable is complete;

FIG. 5 shows the working table of FIG. 4 after a before trigger definedfor another base table is executed;

FIG. 6 shows the working table of FIG. 5 after processing of the otherbase table is complete;

FIG. 7 shows the working table of FIG. 6 after processing of anotherbase table an wherein an ambiguous insertion error has been detected;

FIG. 8 shows the working table of FIG. 7 containing the qualified dataafter all of the base tables have been processed; and

FIGS. 9 a and 9 b show a flowchart of a method in accordance with thepresent invention.

DETAILED DESCRIPTION OF THE EMBODIMENTS

The following discussion refers to a DBMS which employs SQL as at leastone of the mechanisms by which the DBMS can be controlled and operated.However, as will be apparent to those of skill in the art, the presentinvention is not limited to use with DBMS that employ SQL and can infact be used advantageously with any DBMS that offers logical viewsconstructed from union operations on multiple tables.

In the following discussion, an example of a database including salesdata for a corporation is employed. The fields of the sales datacomprises a date, a product ID number, and an amount and the creator ofthe database has decided to physically partition the sales data tablesinto fiscal quarters. A table for the 1^(st) fiscal quarter of 2000 canbe created with the SQL statement:

CREATE TABLE Y00Q1(product_no INT, sales INT, date DATE).

Tables for the remaining three fiscal quarters of 2000 can be createdwith the following SQL statements:

CREATE TABLE Y00Q2 LIKE Y00Q1; CREATE TABLE Y00Q3 LIKE Y00Q1; and CREATETABLE Y00Q4 LIKE Y00Q1;to obtain the necessary tables for the fiscal quarters of year 2000shown. In this example, only the four tables for a single year have beencreated, although as will be apparent to those of skill in the artadditional table for other fiscal quarters can also be created asdesired.

After the four tables are created, a constraint is defined for eachtable to ensure that data entered into the tables meets their intendedpurpose. Specifically, the dates that can be accepted by each table areconstrained to be within the relevant range for each table with thefollowing SQL statements:

ALTER TABLE Y00Q1 ADD CONSTRAINT Y00Q1_CHK_DATE CHECK (MONTH(date) IN(1, 2, 3) AND YEAR(date) = 2000); ALTER TABLE Y00Q2 ADD CONSTRAINTY00Q2_CHK_DATE CHECK (MONTH(date) IN (4, 5, 6) AND YEAR(date) = 2000);ALTER TABLE Y00Q3 ADD CONSTRAINT Y00Q3_CHK_DATE CHECK (MONTH(date) IN(6, 7, 8, 9) AND YEAR(date) = 2000); ALTER TABLE Y00Q4 ADD CONSTRAINTY00Q4_CHK_DATE CHECK (MONTH(date) IN (10, 11, 12) AND YEAR(date) = 2000)

Thus, table Y00Q1 will accept dates in January, February or March of2000, Y00Q2 will accept dates in April, May or June of 2000, Y00Q3 willaccept dates in June, July, August, September of 2000 and Y00Q4 willaccept dates in October, November and December of 2000 and the attemptedentry of dates into a table outside the constrained range applicable forthat table will result in an error. The overlap in the date constraintsfor tables Y00Q2 and Y00Q3, allowing dates in June 2000 to be input intoboth tables, has been specified herein solely for illustrative purposesin the following discussion.

As is known, a view representing the entire Fiscal year 2000 can becreated with:

CREATE VIEW FY2000 AS SELECT product_no, sales, date FROM Y00Q1 UNIONALL SELECT product_no, sales, date FROM Y00Q2 UNION ALL SELECTproduct_no, sales, date FROM Y00Q3 UNION ALL SELECT product_no, sales,date FROM Y00Q4; SELECT * FROM FY

In advanced DBMS systems, such as the above-mentioned DB2 system,INSERTs can be performed on UNION ALL views. However, such INSERTs arenot necessarily easy for the DBMS to perform.

One difficulty is that, when attempting INSERT through UNION ALL views,a before trigger can modify data that one or more fields of data andthat such before triggers are defined on a per table basis. For example,it may be desired to include any sales of product number 9 whichoccurred in the first fiscal quarter into the results for the secondfiscal quarter instead of in the first fiscal quarter. Thus, in thisexample, it is possible to define a constraint for table Y00Q1 toprevent entry of data for product “9”, as follows:

ALTER TABLE Y00Q1 ADD CONSTRAINT Y00Q1_CHK_PRODUCT CHECK ( product_no <>9);and to define a before trigger for table Y00Q2 which, for product “9”changes the date to the first day of the second fiscal quarter, asfollows:

CREATE TRIGGER I_Y00Q2_PN9 NO CASCADE BEFORE INSERT ON Y00Q2 REFERENCINGNEW AS n FOR EACH ROW MODE DB2SQL SET n.date = CASE WHEN (n.product_no =9 AND MONTH(n.date) IN (1, 2, 3) THEN 2000-04-01 ELSE n.date END

Similarly, it may be desired to include any sales of product number 7which occurred in the second fiscal quarter into the results for thefirst fiscal quarter. Thus, in this example, it is possible to define aconstraint for table Y00Q2 to prevent entry of data for product “7”, asfollows:

ALTER TABLE Y00Q2 ADD CONSTRAINT Y00Q2_CHK_PRODUCT CHECK ( product_no <>7);and to define a before trigger for table Y00Q1 which, for product “7”changes the date to the first day of the first fiscal quarter, asfollows:

CREATE TRIGGER I_Y00Q1_PN7 NO CASCADE BEFORE INSERT ON Y00Q1 REFERENCINGNEW AS n FOR EACH ROW MODE DB2SQL SET n.date = CASE WHEN (n.product_no =7 AND MONTH(n.date) IN (4, 5, 6) THEN 2000-01-01 ELSE n.date END.

When an INSERT is performed against a UNION ALL VIEW there are threepossible outcomes, namely: the INSERT can fail against all of the basetables as a no target error (for example, trying to input sales data forfiscal year 2001 into a UNION ALL VIEW of the example tables describedabove would fail as such dates do not meet the constraints of any of thebase tables of the UNION ALL VIEW); the INSERT can fail as being forbeing an ambiguous insert as it can be inserted into more than one basetable of the UNION ALL VIEW (for example, sales data for June 2000 canbe inserted into both of the Y00Q2 and Y00Q3 tables); or the INSERT cansucceed by inserting the data into one and only one of the base tablesfor the UNION ALL VIEW.

If it is desired to add new data to the database through the UNION ALLview, it is necessary for the DBMS to ensure that one, and only one, ofthe above-mentioned three permitted outcomes of the INSERT operation isachieved.

In an embodiment of the present invention, this is achieved in arelatively computationally efficient manner by first determining eachfield in any base table of the UNION ALL view which is modified by abefore trigger. Such fields are referred to herein as “identifiedfields”. In the example above, only the identified field is the datefield which can be modified by the before triggers defined for tablesY00Q1 and Y00Q2.

Once all of the identified fields are determined, then a working tableof the received data is constructed which comprises each of the fieldsof the base tables plus two additional copies of each identified field(in this example the only identified field is the date field, so the twocopies are date_cp1 and date_cp2) and a table ID field (tbl_id) which isalso added, as shown in the row schema of FIG. 1. Data to be INSERTEDthrough the UNION ALL view is loaded into this working table, with thevalue of the identified fields being copied into the first additionalcopy field (in this example, the value of date is copied into date_cp1for each row of received data) and the second additional copy and thetable ID fields (in this example date_cp2 and tbl_id) are each set toNULL.

As will be apparent to those of skill in the art, received data to beinserted into a database through a UNION ALL view can be received in avariety of manners, including SELECT operations, data input, etc. Inthis example, if the data to be INSERTed through the UNION ALL view is:

-   -   7, 20, 2000-05-10;    -   6, 14, 2000-10-03;    -   10, 27, 2000-06-30;    -   9, 18, 2000-02-03        then the working table will be:    -   (7, 20, ‘2000-05-10’, ‘2000-05-10’, -, -)    -   (6, 14, ‘2000-10-03’, ‘2000-10-03’, -, -)    -   (10, 27, ‘2000-06-30’, ‘2000-06-30’, -, -)    -   (9, 18, ‘2000-02-03’, ‘2000-02-03’, -, -)        as shown in FIG. 2.

Next, for each base table in the UNION ALL VIEW in turn, each row of theworking table is processed. First, all before triggers for the basetable are fired (i.e. —processed). In our example, for table F00Q1,trigger I_Y00Q1_PN7 is processed and this modifies the data of theworking table as shown in FIG. 3. Specifically, the first row of theworking table had a product number equal to “7” and a date in Q2, so thevalue of the date field has been set to Jan. 1, 2000. None of the otherrows of the working table are affected by the before trigger defined fortable Y00Q1.

Next the constraints for the base table under consideration areevaluated. For any row which meets all of the constraints for the basetable, the value of the table ID field is checked. If the value of thetable ID field for that row is NULL, then: an identifier for the basetable under consideration is inserted into the table ID field; thebefore trigger processed value of each identified field is copied to theeach respective second copy field, in our example date_cp2; and theoriginal value from each identified field is copied from each respectivefirst copy field, in our example date_cp1, back to each respectiveidentified field.

If the value of the table ID field for that row is not NULL, then themethod returns an error message indicating that that row has suffered anambiguous insertion error. In a present embodiment of the invention, theerror message is returned by storing a pre-selected error code in thetable ID field.

For the working table shown in FIG. 3, row one meets the constraints forinsertion into table Y00Q1 and FIG. 4 shows the working table afterprocessing of table Y00Q1 has completed.

The next base table is now processed in the same manner. Assuming tableY00Q2 is next processed, the before triggers for this table,specifically before trigger I_Y00Q2_PN9, are fired and this modifies thedata of the working table as shown in FIG. 5. Specifically, the fourthrow of the working table had a product number equal to 9 and a date inQ1, so the value of the date field has been set to Apr. 1, 2000.

Next the constraints for the F00Q2 are evaluated. Again, for any rowwhich meets all of the constraints of the base table, the table ID fieldfor that row is checked. If the value of the table ID field for that rowis NULL, then: an identifier for the base table under consideration isinserted into the table ID field; the before trigger processed value ofeach identified field is copied to the respective second copy field, inour example date_cp2; and the original value from each identified fieldis copied from the respective first copy field, in our example date_cp1,back to the respective identified field.

If the value of the table ID field for that row is not NULL, then themethod returns an error message indicating that that row has suffered anambiguous insertion error.

For the working table shown in FIG. 5, rows three and four meet theconstraints for insertion into table Y00Q2 and FIG. 6 shows the workingtable after processing of table Y00Q2 has completed.

The next base table, in this example Y00Q3, is then processed in thesame manner. In this case, no before triggers are defined for tableY00Q3 so the working table is unchanged from that shown in FIG. 6 whenthe next step, evaluating the constraints for table Y00Q3 is performed.As will now be apparent, the third row is the only row of the workingtable that meets the constraints for Y00Q3 so the table ID field forthat row is now checked. As indicated, the table ID field for that rowis not NULL, as that row also fulfilled the criteria for table Y00Q2 andhad an identifier for Y00Q2 inserted into table ID, and the method setsthe table ID field to an error code, as shown in FIG. 7, indicating thatan ambiguous insert result has been obtained and no furtherconsideration of that row need occur.

The next base table, in this example Y00Q4, is then processed, again inthe same manner. Again, in this case no before triggers have beendefined for table Y00Q4 so the working table is unchanged from thatshown in FIG. 7 when the next step, evaluating the constraints for Y00Q4is performed. As can be seen, row two is the only row of the workingtable that meets the constraints of table Y00Q4. The table ID field forrow two is checked and, as the value of the table ID field for that rowis NULL, then: an identifier for table Y00Q4 is inserted into the tableID field; the before trigger processed value of each identified field iscopied to the respective second copy field (in this case this value isunchanged from the original value), in our example date_cp2; and theoriginal value from each identified field is copied from the respectivefirst copy field, in our example date_cp1, back to the respectiveidentified field to obtain the working table illustrated in FIG. 8.

When all base tables have been processed, the method utilizes theworking table to effect the appropriate INSERTs and to generate anynecessary error messages. For each row with a table identifier in itstable ID field, an entry is inserted into the identified table with thefield data in the fields of the row, except for the identified fields.The values in the second copy (in this example, date_cp2) of theidentified fields are used for the values of identified constraintfields, as these values have been processed by the before triggers whichare not triggered again for these INSERT operations.

For any row in the working table with a NULL entry in the table IDfield, a no target error is generated and, for any row with an errorvalue in the table ID field, an ambiguous insert error message isgenerated.

A flowchart of the method of the present invention is shown in FIGS. 9 aand 9 b. As shown, the process commences at step 100 wherein a set ofrecords to be inserted through a UNION ALL view is received. At step104, all of the fields for the base tables of the UNION ALL view, whichcan be modified by a before trigger defined for at least one of the basetables, are identified.

At step 108, two columns are added to the received records for eachidentified field, the added columns to hold copies of the values of therespective identified field.

At step 112, the original value of each identified field is copied tothe first added column and the second added column is set to NULL.

At step 116, a table ID column is added to the received records and thetable ID column rows are set to NULL. At this point, the working tabledescribed above has been constructed.

At step 120, the method begins to process, in turn, each base table ofthe UNION ALL view. At step 124, that processing includes the firing(i.e. —execution) of all triggers that operate on the identified fieldsand can result in modifications to the field data for those identifiedfields but, as described above, a copy of the original data from thoseidentified fields is maintained in the first added column.

At step 128, the method starts, in turn, to consider each row of thereceived data and at step 132 a determination is made as to whether therow under consideration meets the all of the constraints for insertioninto the base table. If the row does not meet one or more of theconstraints for insertion into the base table, then furtherconsideration of that row stops and a determination is made at step 136as to whether additional rows remain to be considered. If one or moreadditional rows remain to be considered, the method selects the next rowat step 128 and the process continues.

If at step 136 no more rows remain to be considered, a determination ismade at step 140 as to whether any more base tables remain to beconsidered. If one or more base tables remain to be considered, at step120 the method selects the next base table to be considered.

At step 132, if a row, after triggering of the before triggers, meetsall of the constraints for insertion into the base table, then adetermination is made at step 144 as to whether the table ID field forthat row is a NULL. If the value of the table ID field is not NULL, thenat step 148 that row is marked for having an ambiguous insert error andthe method proceeds to step 136 to determine if any more rows remain tobe considered.

If at step 144 the table ID field is NULL, then at step 152 the table IDfiled is set to an identifier indicating the base table underconsideration, the identified field values are copied to the second copycolumn (SCC) and the original values are restored to the identifiedfields by copying them from the first copy column (FCC). The method thenproceeds to step 136 to determine if any more rows are to be considered.

At step 140, if no more base tables remain to be considered then themethod concludes at step 156 where the now qualified data is ready forinsertion. If the table ID field for a row contains a valid tableidentifier, then the row is ready for insertion into the identified basetable, using the identified field values stored in the second copycolumn. If the table ID field contains a NULL, a no target error isreturned. If the table ID contains an error flag, then an ambiguousinsert error is returned.

In the first embodiment discussed above, once the received data has beenqualified, it can be inserted without the need to re-fire the beforetriggers applicable to the appropriate base table as the data which hasbeen modified by the before triggers during qualification of thereceived data has been stored in the second copied column. As will beapparent to those of skill in the art that this is merely a preferredimplementation wherein the need to process the before triggers again hasbeen eliminated by the inclusion of an extra column (the second copycolumn) in the working table for each identified field.

The present invention can be employed with only a first copied column(used to store the original value) for each identified field. In thissecond embodiment, after the processing of the working table for thelast base table has completed, the original value of each identifiedfield is replaced, by copying the original value from each respectivefirst copied column to each respective identified field. After theoriginal values have been restored, the qualified data which can beinserted has the relevant before triggers fired for it after which it isinserted as before. In this embodiment, a tradeoff has been made betweenreducing the amount of storage space required for the copies of theidentified fields (only one copy is required versus two) and the amountof computation which must be performed.

In yet another embodiment of the present invention which is a varianteither or both of the first and second embodiments discussed above, onlyfields in the received data which are parameters in a constraint definedfor at least one base table are identified, and these fields arereferred to herein as identified constraint fields. In processing thereceived data in this embodiment, copies (two copies for this variant ofthe first embodiment discussed above and a single copy for this variantof the second embodiment discussed above) are only added to the workingtable for these identified constraint fields.

In this variant of the first embodiment, once qualification of thereceived data is complete, prior to insertion of the received data intothe appropriate base tables, before triggers defined for the target basetable into which the received data is to be inserted are fired for allfields except the identified constraint fields. The results from thesebefore triggers and the results stored in the second copy column for theidentified constraint fields are then inserted into the target basetable along with any other fields. This variant saves the computationrequired to re-fire the identified constraint fields and saves storagespace in the working table by only requiring copy columns to be addedfor identified constraint fields and not requiring copy columns to beadded for all identified fields.

In this variant of the second embodiment, only one copy column isemployed and once qualification of the received data is complete, priorto insertion of the received data into the appropriate base tables, allbefore triggers defined for the target base table into which thereceived data is to be inserted are fired. The results from these beforetriggers are then inserted into the target base table along with anyother fields. This variant saves storage space in the working table byonly requiring one copy columns to be added for identified constraintfields and not requiring copy columns to be added for all identifiedfields.

It is also contemplated that, in another embodiment, all fields in therows of the received data will be copied, either one of the single ordouble copy embodiments described above, thus eliminating thecomputation required to determine which fields will be modified by abefore trigger at the expense of requiring additional storage space forthe copies in many cases.

The present invention is not limited to use with the DB2 database andcan be used with any DBMS that provides functionality similar to a UNIONALL View formed from the union of two or more base tables. Further, thepresent invention is not limited to DBMSes which employ SQL as a controlmechanism and the present invention can also be applied to DBMSes whichemploy any other suitable control method. In such cases, appropriatefeatures in those control mechanisms which are equivalent to beforetriggers, constraints and the other specific SQL features referred toherein can be employed.

The above-described embodiments of the invention are intended to beexamples of the present invention and alterations and modifications maybe effected thereto, by those of skill in the art, without departingfrom the scope of the invention which is defined solely by the claimsappended hereto.

1-4. (canceled)
 5. A computer program product for directing a dataprocessing system to process a record to be inserted into a database,the database comprising a plurality of base tables, the computer programproduct comprising: a computer readable medium tangibly embodyingcomputer executable code for directing the data processing system, thecomputer executable code comprising: code for making a record copymatching the record; code to be executed for each base table to beselected from the plurality of base tables, the code to be executedcomprising: code for providing a base table candidate indication for aselected base table, the base table candidate indication indicatingwhether the selected base table is a candidate base table that mayreceive the record, the base table candidate indication being determinedon an outcome of executing before triggers and an outcome of testingconstraints on the record copy, the before triggers and the constraintsbeing associated with the selected base table and the base tablecandidate indication being recorded in a computer-readable storagemedium; and code for restoring the record copy so that the record copymatches the record before providing a next subsequent base tablecandidate indication for another base table to be selected.
 6. Thecomputer program product of claim 5 wherein: the record comprises rows;the code for providing comprises: code for executing before triggersassociated with the selected base table for each row of the record copy,the executed before triggers altering the record copy; and code fortesting constraints associated with the selected base table against thealtered record copy.
 7. The computer program product of claim 5 furthercomprising: code for associating the plurality of base tables with allunion view of the plurality of base tables.
 8. The computer programproduct of claim 5 further comprising: code for inserting the receivedrecord into a base table if the base table is the only base tableindicated as the candidate base table; and code for issuing an errormessage if there are more than one base table indicated as the candidatebase table. 9-20. (canceled)